package com.example.chatbot.repository;

import com.example.chatbot.entity.ChatInfo;
import org.springframework.stereotype.Repository;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Repository
public class MemoryChatHistoryRepository implements ChatHistoryRepository {
    private final Map<String, ChatInfo> chatHistory = new LinkedHashMap<>();

    @Override
    public void save(String chatId, ChatInfo chatInfo) {
        // 覆盖相同的 chatId 信息, 保存最后一次消息信息
        chatHistory.put(chatId, chatInfo);
    }

    @Override
    public List<ChatInfo> getChatList() {
        return chatHistory.values().stream().toList();
    }

    @Override
    public void deletedChatId(String chatId) {
        chatHistory.remove(chatId);
    }
}
